//使用前请修改store & column 对应字段
Ext.onReady(function() {
//查询任务start------------------------------------------------
assignmentstore = new Ext.data.Store({
				url : 'workflowTaskAction.action?actionType=0&flag=1',
				reader : new Ext.data.JsonReader({
							root : 'result.result',
							//id: 'flow_insid',
							totalProperty : 'result.totalCount'
						}, [{
								name : 'flow_insid',
								mapping : 'flow_insid'
							},{
								name : 'flow_id',
								mapping : 'flow_id'
							},{
								name : 'step_id',
								mapping : 'step_id'
							},{
								name : 'flow_url',
								mapping : 'flow_url'
							},{
								name : 'company_code',
								mapping : 'company_code'
							},{
								name : 'flow_name',
								mapping : 'flow_name'
							}, {
								name : 'priod',
								mapping : 'priod'
							}, {
								name : 'step_name',
								mapping : 'step_name'
							},{
								name : 'step_type',
								mapping : 'step_type'
							}, {
								name : 'flow_at',
								mapping : 'flow_at'
							}, {
								name : 'flow_status',
								mapping : 'flow_status'
							}, {
								name : 'this_company',
								mapping : 'this_company'
							}, {
								name : 'company_chinese_code',
								mapping : 'company_chinese_code'
							}, {
								name : 'pre_insid',
								mapping : 'pre_insid'
							}, {
								name : 'step_runtype',
								mapping : 'step_runtype'
							}, {
								name : 'step_role',
								mapping : 'step_role'
							}, {
								name : 'step_user',
								mapping : 'step_user'
							}])  
				        });
					        
companyStore1 = new Ext.data.Store({
				url : 'workflowTaskAction.action?actionType=0&flag=4',
				reader : new Ext.data.JsonReader({
							root : 'resultL',
							id: 'returnValue'
						}, [{
									name : 'returnValue',
									mapping : 'returnValue'
								},{
									name : 'displayText',
									mapping : 'displayText'
								}])  
					        });
Ext.namespace('Ext.Tasks');
Ext.Tasks.flow_status = [['A', '运行'], ['R', '退回'], ['E', '结束']];
statusStore = new Ext.data.SimpleStore({
							fields : ['key', 'value'],
							data : Ext.Tasks.flow_status
						});				        					      
var assignmentcm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
				header : '实例标识',
				width : 90,
				hidden:true,
				dataIndex : 'flow_insid'
			},{
				header : '流程标识',
				width : 90,
				hidden:true,
				dataIndex : 'flow_id'
			},{
				header : '步骤标识',
				width : 90,
				hidden:true,
				dataIndex : 'step_id'
			},{
				header : '对应分公司链接',
				width : 90,
				hidden:true,
				dataIndex : 'flow_url'
			},{
				header : '对应分公司',
				width : 90,
				hidden:true,
				dataIndex : 'company_code'
			},{
				header : '流程名称',
				width : 90,
				dataIndex : 'flow_name'
			},{
				header : '期间',
				width : 90,
				dataIndex : 'priod'
			},{
				header : '所在步骤',
				width : 90,
				dataIndex : 'step_name'
			},{
				header : '步骤类型',
				width : 90,
				dataIndex : 'step_type',
				renderer:step_type
			},{
				header : '流程状态',
				dataIndex : 'flow_at',
				renderer:flow_at
			},{
				header : '审核状态',
				dataIndex : 'flow_status',
				renderer:flow_status
			}, {
				header : '下辖公司',
				hidden:true,
				dataIndex : 'this_company'
			}, {
				header : '下辖公司名称',
				hidden:true,
				dataIndex : 'company_chinese_code'
			}, {
				header : '前一实例标识',
				hidden:true,
				dataIndex : 'pre_insid'
			}, {
				header : '执行人类型',
				hidden:true,
				dataIndex : 'step_runtype'
			}, {
				header : '执行角色',
				hidden:true,
				dataIndex : 'step_role'
			}, {
				header : '执行人',
				hidden:true,
				dataIndex : 'step_user'
			}]);
function flow_at(val){
    if(val=='1'){
        return '分公司级别审核';
    }else if(val == '2'){
        return '大区级别审核';
    }else if(val == '3'){
        return '集团级别审核';
    }
    return val;
}	
function flow_status(val){
    if(val=='A'){
        return '运行';
    }else if(val == 'R'){
        return '退回';
    }else if(val == 'E'){
        return '结束';
    }
    return val;
}	
function step_type(val){
    if(val=='S'){
        return '开始步骤';
    }else if(val == 'E'){
        return '结束步骤';
    }else if(val == 'P'){
        return '中间步骤';
    }
    return val;
}		
var assignmentGrid = new Ext.grid.GridPanel({
				title:'任务列表',
				trackMouseOver:true, 
				stripeRows:true, 
				autoScroll:true, 
				hideCollapseTool:true, 
				collapsible:true, 
				titleCollapse:true, 
				bufferResize:true, 
				loadMask:true, 
				id : 'assignmentGrid',
				tbar:['对应期间:',
				   {
							xtype:'textfield',
							id:'priodq'
					},
					{xtype:"tbseparator"},
					'对应分公司:',
					{
						xtype : 'combo',
						store:companyStore1,
						valueField :"returnValue",   
    					displayField: "displayText",  
						name : 'compand_codeq',
						id : 'compand_codeq',
						anchor : '50%',
						emptyText : '请选择分公司名称',
						triggerAction: 'all',
						editable: false
					},
					{xtype:"tbseparator"},
					'流程状态:',
					{
						xtype : 'combo',
						store:statusStore,
						valueField :"key",   
    					displayField: "value",   
						name : 'flow_statusq',
						id : 'flow_statusq',
						anchor : '50%',
						mode:'local',
						emptyText : '请选择状态',
						triggerAction: 'all',
						editable: false,
						value:'A'
					},
					{xtype:"tbseparator"},
					{
						xtype : 'button',
						text : '查询',
						handler : function() {
							assignmentstore.on('beforeload', function() {
										assignmentstore.baseParams = {
											'filter.priod' : Ext.getCmp('priodq').getValue(),
											'filter.company_code' : Ext.getCmp('compand_codeq').getValue(),
											'filter.flow_status' : Ext.getCmp('flow_statusq').getValue()
										}
									});
							assignmentstore.reload();
						}
					},
					{xtype:"tbseparator"},
					{xtype:"tbbutton",
						   text:"新建审核",
						   id:'new_admit',
						   handler:function(){
						   		Ext.getCmp('companyassignmentForm').getForm().reset();
								Ext.getCmp('companyassignmentForm').findById('priod').enable();
								Ext.getCmp('companysave').enable();
								Ext.getCmp('companypass').disable();
								Ext.getCmp('companyrollback').disable();
						   		Ext.Ajax.request({
									url : 'workflowTaskAction.action?actionType=0&flag=2',
									method : 'post',
									success : function(response, options) {
										var responseTextVale = Ext.util.JSON.decode(response.responseText);
										if(responseTextVale.isOk>0){
											Ext.getCmp('companyPayClass').getStore().removeAll();
											Ext.getCmp('companyassignmentForm').findById('flow_at').setValue(1);
											Ext.getCmp('companyassignmentForm').findById('flow_memos').disable();
											companyassignmentWin.show();
										}else{
											Ext.Msg.show({
													title : '操作信息',
													msg : '你没有新建审批的权限,请联系管理员！',
													buttons : Ext.Msg.OK
												});
										}
									},
									failure : function(response, options) {
										Ext.Msg.show({
													title : '操作信息',
													msg : '数据处理异常,请联系管理员',
													buttons : Ext.Msg.OK
												});
									}
								});
						   }
				   }
			    ],bbar : new Ext.PagingToolbar({
							pageSize : pageSize,
							store : assignmentstore,
							displayInfo : true,
							dispalyMsg : '显示第{0}条到{1}条记录，一共{2}条',
							emptyMsg : '没有记录'
						}),
				cm : assignmentcm,
				store : assignmentstore,
				loadMask : true,
				loadMask : {
					msg : '正在加载数据...'
				}
			});	
assignmentGrid.addListener('rowdblclick', rowdblclickFn);
function rowdblclickFn(grid, rowIndex, e) {
	record=grid.getStore().getAt(rowIndex).data;
	if(record.flow_url==2){
		Ext.getCmp('companyPayClass').getStore().on('beforeload', function() {
			Ext.getCmp('companyPayClass').getStore().baseParams = {
				'actionType' : 0,
				'flag' : 5,
				'filter.company_code' : record.company_code,
				'filter.priod' : record.priod
			}
		});
		Ext.getCmp('companyPayClass').getStore().reload();
		companyassignmentWin.show();
		Ext.getCmp('companyassignmentForm').findById('company_code').setValue(record.company_code);
		Ext.getCmp('companyassignmentForm').findById('priod').disable();
		Ext.getCmp('companyassignmentForm').findById('priod').setValue(record.priod);
		Ext.getCmp('companyassignmentForm').findById('flow_at').setValue(record.flow_at);
		Ext.getCmp('companyassignmentForm').findById('flow_id').setValue(record.flow_id);
		Ext.getCmp('companyassignmentForm').findById('flow_insid').setValue(record.flow_insid);
		Ext.getCmp('companyassignmentForm').findById('step_id').setValue(record.step_id);
		if(record.flow_status=='E'){
			Ext.getCmp('companysave').disable();
			Ext.getCmp('companypass').disable();
			Ext.getCmp('companyrollback').disable();
		}else{
			Ext.getCmp('companysave').disable();
			Ext.getCmp('companypass').enable();
			if(record.pre_insid==''&&record.step_type=='S'){
				Ext.getCmp('companyrollback').disable();
			}else{
				Ext.getCmp('companyrollback').enable();
			}
			if(record.step_runtype==1&&record.step_user==session_userId){
				
			}else{
				var finishflag=0;
				for(var i=0;i<roles.length;i++){
					if(roles.get(i)==session_userId){
						finishflag=1;break;
					}
				}
				if(finishflag==0){
					Ext.getCmp('companypass').disable();
					Ext.getCmp('companyrollback').disable();
				}
			}
		}
	}else if(record.flow_url==1){
		Ext.getCmp('AreaPayClass').getStore().on('beforeload', function() {
			Ext.getCmp('AreaPayClass').getStore().baseParams = {
				'actionType' : 0,
				'flag' : 6,
				'filter.company_code' : record.company_code,
				'filter.priod' : record.priod
			}
		});
		Ext.getCmp('AreaPayClass').getStore().reload();
		areaassignmentWin.show();
		Ext.getCmp('areaassignmentForm').findById('priod').disable();
		Ext.getCmp('areaassignmentForm').findById('company_code').setValue(record.company_code);
		Ext.getCmp('areaassignmentForm').findById('priod').setValue(record.priod);
		Ext.getCmp('areaassignmentForm').findById('flow_at').setValue(record.flow_at);
		Ext.getCmp('areaassignmentForm').findById('flow_id').setValue(record.flow_id);
		Ext.getCmp('areaassignmentForm').findById('flow_insid').setValue(record.flow_insid);
		Ext.getCmp('areaassignmentForm').findById('step_id').setValue(record.step_id);
		if(record.company_chinese_code!=''||record.company_chinese_code!=null){
			Ext.getCmp('areaassignmentForm').findById('this_company').setValue(record.company_chinese_code);
		}
		if(record.flow_status=='E'){
			Ext.getCmp('companypass1').disable();
			Ext.getCmp('companyrollback1').disable();
		}else{
			Ext.getCmp('companypass1').enable();
			Ext.getCmp('companyrollback1').enable();
			if(record.step_runtype==1&&record.step_user==session_userId){
				
			}else{
				var finishflag=0;
				for(var i=0;i<roles.length;i++){
					if(roles.get(i)==session_userId){
						finishflag=1;break;
					}
				}
				if(finishflag==0){
					Ext.getCmp('companypass1').disable();
					Ext.getCmp('companyrollback1').disable();
				}
			}
		}
	}else{
		Ext.getCmp('GroupPayClass').getStore().on('beforeload', function() {
			Ext.getCmp('GroupPayClass').getStore().baseParams = {
				'actionType' : 0,
				'flag' : 7,
				'filter.company_code' : record.company_code,
				'filter.priod' : record.priod
			}
		});
		Ext.getCmp('GroupPayClass').getStore().reload();
		groupassignmentWin.show();
		Ext.getCmp('groupassignmentForm').findById('priod').disable();
		Ext.getCmp('groupassignmentForm').findById('company_code').setValue(record.company_code);
		Ext.getCmp('groupassignmentForm').findById('priod').setValue(record.priod);
		Ext.getCmp('groupassignmentForm').findById('flow_at').setValue(record.flow_at);
		Ext.getCmp('groupassignmentForm').findById('flow_id').setValue(record.flow_id);
		Ext.getCmp('groupassignmentForm').findById('flow_insid').setValue(record.flow_insid);
		Ext.getCmp('groupassignmentForm').findById('step_id').setValue(record.step_id);
		if(record.company_chinese_code!=''||record.company_chinese_code!=null){
			Ext.getCmp('groupassignmentForm').findById('this_company').setValue(record.company_chinese_code);
		}
		if(record.flow_status=='E'){
			Ext.getCmp('companypass12').disable();
			Ext.getCmp('companyrollback2').disable();
		}else{
			Ext.getCmp('companypass2').enable();
			Ext.getCmp('companyrollback2').enable();
			if(record.step_runtype==1&&record.step_user==session_userId){
				
			}else{
				var finishflag=0;
				for(var i=0;i<roles.length;i++){
					if(roles.get(i)==session_userId){
						finishflag=1;break;
					}
				}
				if(finishflag==0){
					Ext.getCmp('companypass2').disable();
					Ext.getCmp('companyrollback2').disable();
				}
			}
		}
	}	
}

assignmentstore.on('beforeload', function() {
assignmentstore.baseParams = {
		'filter.priod' : '',
		'filter.company_code' : session_companyName,
		'filter.flow_status' : 'A'
	}
});
assignmentstore.reload();

//查询任务end------------------------------------------------	

Ext.Ajax.request({
	url : 'workflowTaskAction.action?actionType=0&flag=3',
	method : 'post',
	success : function(response, options) {
		new Ext.Viewport({layout:"fit", items:[assignmentGrid]});
		var responseTextVale = Ext.util.JSON.decode(response.responseText);
		if(responseTextVale.isOk>0){
			Ext.getCmp('new_admit').disable();
		}else{
			Ext.getCmp('new_admit').enable();
		}
	},
	failure : function(response, options) {
		new Ext.Viewport({layout:"fit", items:[assignmentGrid]});
		Ext.getCmp('new_admit').disable();
	}
});	
});